package com.bindapp.model;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import com.bindapp.R;
import com.bindapp.activity.AboutUsActivity;
import com.bindapp.activity.SettingActivity;
import com.bindapp.bean.AppUser;
import com.bindapp.databinding.FragmentMaintab4Binding;
import com.bindapp.http.MNetHttp;
import com.bindapp.listener.HttpListener;
import com.bindapp.listener.LoadStatusListener;
import com.bindapp.util.Static;

import java.util.HashMap;

/**
 * Created by tom055 on 2018/6/3.
 */

public class Tab4Model extends BaseModel {
    private FragmentMaintab4Binding binding;
    private LoadStatusListener listener;

    public Tab4Model(Context context, LoadStatusListener listener){
        super(context);
        this.listener=listener;
        binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.fragment_maintab4,null,false);
        binding.setClick(new ViewClick());
    }

    public void postRequest(){
        Log.e("Mytext","-->"+Static.Cookie);
        String url= Static.APPUser;
        MNetHttp.getInstance(context).rxGetRequest(Static.APPUser, AppUser.class, new HttpListener() {
            @Override
            public void success(Object obj) {
                if(((AppUser)obj).isSuccess()&&((AppUser)obj).isBl()){
                    listener.show();
                    binding.name.setText(((AppUser)obj).getData().getRows().get(0).getName());
                    binding.noid.setText(((AppUser)obj).getData().getRows().get(0).getPhoneNumber());
                    if(((AppUser)obj).getData().getRows().get(0).getGender().equals("男")){
                        binding.seximg.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.nan));
                    }else{
                        binding.seximg.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.nv));

                    }
                }else{
                    listener.hide(false,((AppUser)obj).getMsg());
                    //Static.showToast(context,((AppUser)obj).getMsg());
                }

            }

            @Override
            public void fail(String msg) {
                listener.hide(false,msg);
            }
        });
    }

    @Override
    public FragmentMaintab4Binding getBinding(){
        return binding;
    }

    public class ViewClick{
        public void onClick(View view){

            switch(view.getId()){
                case R.id.item4:
                    turnToVc(AboutUsActivity.class,new HashMap<String, Object>());
                    break;
                case R.id.item5:
                    turnToVc(SettingActivity.class,new HashMap<String,Object>());
                    break;
            }
        }
    }


}
